<?php
	/**
	This file is part of PEL.
		PEL is free software: you can redistribute it and/or modify
		it under the terms of the GNU General Public License as published by
		the Free Software Foundation, either version 3 of the License, or
		(at your option) any later version.
	    
		PEL is distributed in the hope that it will be useful,
		but WITHOUT ANY WARRANTY; without even the implied warranty of
		MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
		GNU General Public License for more details.
	    
		You should have received a copy of the GNU General Public License
		along with PEL.  If not, see <http://www.gnu.org/licenses/>.
	* Elgg pel: delete lang action
	*/

// Make sure we're logged in (send us to the front page if not)
	gatekeeper();
// Get input data
	$guid = (int) get_input('post');
	
// Make sure we actually have permission to edit
	$lang = get_entity($guid);
	if ($lang->getSubtype() == "lang" && $lang->canEdit()){
		// Get owning user
		$owner = get_entity($lang->getOwner());
    // Delete it!
		$rowsaffected = $lang->delete();
		if ($rowsaffected > 0){
      // Success message
			system_message(elgg_echo("pel:deleted"));
		}
    else{
			register_error(elgg_echo("pel:notdeleted"));
		}
    // Forward to the main pel page
    forward("mod/pel/?username=" . $owner->username);
	}
?>